package maven.jyhs.com.servlet;


import com.alibaba.fastjson2.JSON;
import maven.jyhs.com.entity.User;
import maven.jyhs.com.proxy.dynamic.CglibProxyFactory;
import maven.jyhs.com.proxy.dynamic.CglibProxyInterceotor;
import maven.jyhs.com.servce.TranstfeSevrce;
import maven.jyhs.com.servce.impl.TranstfeSevrceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet(urlPatterns = "/transtfeServlet")
public class TranstfeServlet extends HttpServlet {
    TranstfeSevrce service = CglibProxyFactory.createProxy(new TranstfeSevrceImpl());

    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8");
        resp.setCharacterEncoding("UTF-8");

        try {

            PrintWriter writer = null;
            writer = resp.getWriter();
            List<User> users = service.gather();
            writer.print(JSON.toJSON(users));
            writer.flush();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
